<template>
    <view>
        <u--form :model="info" :rules="rules" ref="uForm" labelWidth="120">
            <u-form-item label="客户来源名称：" prop="name">
                <u--input v-model="info.name" border="bottom"></u--input>
            </u-form-item>

            <u-button type="primary" text="提交"></u-button>
        </u--form>

        <u-toast ref="uToast"></u-toast>
    </view>
</template>
<script>
export default {
    data() {
        return {
            id: 0,
            info: {
                name:''
            },
            LoginAdmin: {},
            rules:{
                name:{
                    type:'string',
                    required: true,
					message: '请填写客户来源名称',
					trigger: ['blur', 'change']
                }
            }
        }
    },
    methods: {
        async getInfo() {
            let data = {
                adminid: this.LoginAdmin.id,
                id: this.id
            }

            let result = await this.$u.api.manage.sourceInfo(data);

            if(result && result.code === 0)
            {
                this.$refs.uToast.show({
                    type:'error',
                    message:result.msg,
                    complete:() => {
                        this.$u.route({
                            type:'back'
                        });
                    }
                });

                return;
            }

            this.info = result.data;
        }
    },
    onLoad(options) {
        this.id = options.id || 0;

        this.LoginAdmin = uni.getStorageSync('admin') || 0;

        this.getInfo();
    },
    onReady() {
		//onReady 为uni-app支持的生命周期之一
    	this.$refs.uForm.setRules(this.rules)
    },

}
</script>